<?
$data = json_decode(@file_get_contents("php://input"), true);


$id = $data['id'];

$url = "http://cache.neea.edu.cn/Imgs.do?c=CET&ik=".$id."&t=0.222";

$ch = curl_init();
$user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_REFERER, "http://cet.neea.edu.cn/cet/");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return_content = curl_exec($ch);
curl_close($ch);

//var_dump($return_content);

list($header, $body) = explode("\r\n\r\n", $return_content);

preg_match('/Set-Cookie:(.*);/iU', $return_content, $str); //正则匹配

$cookie = $str[1]; //获得COOKIE（SESSIONID）

/*-----使用COOKIE-----*/
//curl_setopt($ch,CURLOPT_COOKIE,$cookie);

$img =  "http://cet.neea.edu.cn/imgs/".explode("\")",explode("(\"", $body)[1])[0].".png";

$arr = array('err'=>0,'img'=>$img,"session"=> $cookie);

exit(json_encode($arr)); 
// $curl = curl_init();
// curl_setopt($curl, CURLOPT_URL, $url);
// curl_setopt($curl,CURLOPT_COOKIE,$cookie);
// curl_setopt($curl, CURLOPT_HEADER, 0);
// curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// $img = curl_exec($curl);
// curl_close($curl);
